#include <cstdio>
#include <iostream>

using std::cout;
using std::cin;

int maxT(int* tl,int* pre,int lc,int level,int maxlevel){	//lc is last cacl max array count ,level is current level number , level 1,2,3
	cout<<"last calc:\n";
	for(int i=0;i<lc;i++){
		cout<<pre[i]<<"  ";
	}
	cout<<"\n";
	
	if(level>maxlevel){
		//find max
		int max=0;
		for(int i=0;i<lc;i++){
			if(pre[i]>max)
				max=pre[i];
		}
		return max;
	}
	
	int ccl=(level-1)*2;
	int* next=(int*)malloc(sizeof(int)*ccl);
	int cc=0;
	int* tp=tl;
	tl+=level*(level-1)/2;
	int ll=level;
	for(int i=0;i<lc;i++){
		int c=*tl;
		int cn=*(tl+1);
		next[cc++]=pre[i]+c;
		next[cc++]=pre[i]+cn;
		tl+=1;
	}
	tl=tp;
	return maxT(tl,next,ccl,level+1,maxlevel);
}

int getMax(int* data,int level,int total){	
	/*for(int i=0;i<len;i++){
		int* pre=(int*)malloc(sizeof(int)*(i+1));
	}
	*/
	int pre[]={data[0]};
	return maxT(data,pre,1,2,level);
}


int main(){
	cout<<"input number:\n";
	int level=0;
	cin>>level;
	
	int total=(1+level)*level/2;
	cout<<"total is "<<total<<"\n";
	
	/*
	int* data=(int*)malloc(sizeof(int)*total);

	int cc=0;
	for(int i=1;i<=len;i++){
		for(int j=0;j<i;j++){
			int t;
			cin>>t;
			data[cc++]=t;
		}
	}*/
	int data[]={7,
				3,8,
				8,1,0,
				2,7,4,4,
				4,5,2,6,5};			
	
	for(int i=0;i<total;i++){
		cout<<data[i]<<"\t";
	}
	
	int max=getMax(data,level,total);
	cout<<"max is "<<max<<"\n";
}
